package ph.com.gs3.formalistics.model.valueobjects.business.document;

import java.util.List;

import org.json.JSONObject;

public class OutgoingDocument implements AbstractDocument {

	private String id;
	private String server;
	private String documentFormWebId;
	private String documentWebId;

	private String documentFormName;

	private String issuedByUserId;
	private String dateIssued;
	private JSONObject fieldValues;
	private String action;
	private String errorMessage;

	// =======================================================================================
	// {{ Static Builder Methods

	public static OutgoingDocument createFromDocument(Document document, String formName,
	        String action, String issuedByUserId) {

		OutgoingDocument outgoingDocumentAction = new OutgoingDocument();

		outgoingDocumentAction.setServer(document.getServer());
		outgoingDocumentAction.setDocumentWebId(document.getWebId());
		outgoingDocumentAction.setDocumentFormWebId(document.getFormWebId());

		outgoingDocumentAction.setDocumentFormName(formName);

		outgoingDocumentAction.setIssuedByUserId(issuedByUserId);
		outgoingDocumentAction.setDateIssued(null);	// will be set by the DAO upon saving
		outgoingDocumentAction.setFieldValues(document.getFields());
		outgoingDocumentAction.setAction(action);
		outgoingDocumentAction.setErrorMessage(null);

		return outgoingDocumentAction;

	}

	public static OutgoingDocument createAsNewDocumentToSubmitAction(String server,
	        String formWebId, String formName, String action, String issuedByUserId,
	        JSONObject fieldValues) {

		OutgoingDocument outgoingDocumentAction = new OutgoingDocument();

		outgoingDocumentAction.setServer(server);
		outgoingDocumentAction.setDocumentWebId("0");
		outgoingDocumentAction.setDocumentFormWebId(formWebId);

		outgoingDocumentAction.setDocumentFormName(formName);

		outgoingDocumentAction.setIssuedByUserId(issuedByUserId);
		outgoingDocumentAction.setDateIssued(null);	// will be set by the DAO upon saving
		outgoingDocumentAction.setFieldValues(fieldValues);
		outgoingDocumentAction.setAction(action);
		outgoingDocumentAction.setErrorMessage(null);

		return outgoingDocumentAction;

	}

	// }}

	// =======================================================================================
	// {{ Getters & Setters
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getDocumentFormWebId() {
		return documentFormWebId;
	}

	public void setDocumentFormWebId(String documentFormId) {
		this.documentFormWebId = documentFormId;
	}

	public String getDocumentWebId() {
		return documentWebId;
	}

	public void setDocumentWebId(String documentDbId) {
		this.documentWebId = documentDbId;
	}

	public String getDateIssued() {
		return dateIssued;
	}

	public void setDateIssued(String dateIssued) {
		this.dateIssued = dateIssued;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public String getErrorMessage() {
		return errorMessage;
	}

	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}

	public String getIssuedByUserId() {
		return issuedByUserId;
	}

	public void setIssuedByUserId(String issuedByUserId) {
		this.issuedByUserId = issuedByUserId;
	}

	public JSONObject getFieldValues() {
		return fieldValues;
	}

	public void setFieldValues(JSONObject fieldValues) {
		this.fieldValues = fieldValues;
	}

	public String getServer() {
		return server;
	}

	public void setServer(String server) {
		this.server = server;
	}

	public String getDocumentFormName() {
		return documentFormName;
	}

	public void setDocumentFormName(String documentFormName) {
		this.documentFormName = documentFormName;
	}

	// }}

	@Override
	public boolean isStarred() {
		return false;
	}

	@Override
	public JSONObject getFields() {
		return fieldValues;
	}

	@Override
	public String getWebId() {
		// return DEFAULT_UNSUBMITTED_DOCUMENT_WEB_ID;
		return documentWebId;
	}

	@Override
	public List<String> getFieldsEnabled() {
		return null;
	}

	@Override
	public List<String> getFieldsHidden() {
		return null;
	}

	@Override
	public List<String> getFieldsRequired() {
		return null;
	}

	@Override
	public DocumentType getDocumentType() {
		return DocumentType.OUTGOING;
	}

}
